#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

//sort:对容器内元素进行排序
//函数原型：sort(iterator beg, iterator end, _Pred);
//beg    开始迭代器   end    结束迭代器   _Pred  谓词

void myPrint(int val) {
    cout << val << " ";
}

void test() {
    vector<int> v;
    v.push_back(10);
    v.push_back(30);
    v.push_back(50);
    v.push_back(20);
    v.push_back(40);

    sort(v.begin(), v.end());//sort默认从小到大排序
    for_each(v.begin(), v.end(), myPrint);
    cout << endl;

    sort(v.begin(), v.end(), greater<int>());
    for_each(v.begin(), v.end(), myPrint);
    cout << endl;

}

int main() {
    test();
    return 0;
}